package com.neusoft.bizcore.activiti.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "wf_process")
@org.hibernate.annotations.Table(appliesTo = "wf_process", comment = "业务流程表")
public class Process extends AbstractModel {

    private static final long serialVersionUID = 1L;

    @NotBlank(message = "业务流程名不能为空")
    @Length(max = 255, message = "业务流程名不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '业务流程名称'")
    private String name;

    @NotBlank(message = "业务流程编码不能为空")
    @Length(max = 255, message = "业务流程编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '业务流程编码'")
    private String code;

    /** 关联表单 */
    @ManyToMany
    @JoinTable(name = "wf_ref_process_form")
    @LazyCollection(LazyCollectionOption.FALSE)
    List<ProcessForm> formList = new ArrayList<>();

    /** 关联角色 */
    @OneToMany(mappedBy = "process", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<ProcessRole> roles = new ArrayList<>();
}
